package inter.controller;

import inter.authorization.annotation.Authorization;
import inter.authorization.manager.AppSecretManager;
import inter.authorization.model.AppSecretModel;
import inter.config.ResultStatus;
import inter.model.ResultModel;

import com.dingpeikeji.quickdeer.core.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 获取和删除appSecret的请求地址，在Restful设计中其实就对应着登录和退出登录的资源映射
 * 
 * @author Max
 * @date 2016/10/24.
 */
@Controller
@RequestMapping(value = "/appSecret")
public class AppSecretController {

	@Autowired
	private AppSecretManager appSecretManager;

	@RequestMapping(value="login", method = RequestMethod.GET)
	public ResponseEntity<ResultModel> login(@RequestParam String username, @RequestParam String password) {

		
		AppSecretModel model = appSecretManager.createAppSecret(username);

		return new ResponseEntity<ResultModel>(ResultModel.ok(model), HttpStatus.OK);
	}

	@RequestMapping(value="logout", method = RequestMethod.GET)
	@Authorization
	public ResponseEntity<ResultModel> logout(@RequestParam String userid) {
		appSecretManager.deleteAppSecret(userid);
		return new ResponseEntity(ResultModel.ok(), HttpStatus.OK);
	}

}